package test02;

public class Shouhu implements Runnable {
    private User user;

    public Shouhu(User user) {
        this.user = user;
    }

    @Override
    public void run() {
        while (!user.isFinished()) { // 只要没拷贝完，就一直监视
            long copied = user.getCopiedSize();
            long total = user.getTotalSize();
            double percentage = (copied * 100.0) / total; // 计算进度百分比

            // 显示进度（单位：MB）
            System.out.printf("拷贝进度: %.2f%%\n", percentage);

            try {
                Thread.sleep(500); // 每200ms更新一次进度
            } catch (InterruptedException e) {
                break;
            }
        }
    }
}
